package com.alibaba.citrus.ots.forecast.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import com.alibaba.citrus.ots.forecast.repository.DictValuesQueryRepository;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.otsplatformenhance.domain.dictvalue.model.DictValue;
import com.epoch.app.otsplatformenhance.domain.dictvalue.service.DictValueService;
import com.epoch.app.otsplatformenhance.model.dto.DictValueLoadListRequest;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: qianlei
 * @create: 2021/10/19 23:41
 */
@Component
public class DictValuesQueryRepositoryImpl implements DictValuesQueryRepository {
    @Resource
    DictValueService dictValueService;
    @Override
    public Map<String, String> queryValues(String code) {
        DictValueLoadListRequest valueLoadListRequest = new DictValueLoadListRequest();
        valueLoadListRequest.setDictCode(code);

        Result<List<DictValue>> result = dictValueService.loadDictValueList(valueLoadListRequest);

        if (result != null && !CollectionUtils.isEmpty(result.getResult())) {
            return  result.getResult().stream().collect(Collectors.toMap(DictValue::getValueData,DictValue::getValueName));
        }
        return new HashMap<>();
    }
}
